package mysql

import (
	"gorm.io/gorm"
)

type Good struct {
	gorm.Model
	UserId     int     `gorm:"type:int;not null;comment:'用户Id'"`
	GoodsTitle string  `gorm:"type:varchar(50);not null;comment:'商品标题'"`
	GoodsStock int     `gorm:"type:int;not null;comment:'商品库存'"`
	GoodsImage string  `gorm:"type:varchar(255);not null;comment:'商品图片'"`
	GoodsPrice float64 `gorm:"type:double(10,2);not null;comment:'商品价格'"`
	GoodsLike  int     `gorm:"type:int;not null;comment:'点赞数量'"`
	Status     int     `gorm:"type:int;not null;comment:状态:1-审核,2-未审核"`
}

func (g *Good) Create() error {
	return DB.Create(&g).Error
}
func (g *Good) GetGood(Page, PageSize, Status int) (good []Good, err2 error) {
	if Status == 0 {
		DB.Offset((Page - 1) * PageSize).Limit(PageSize).Find(&good)
	} else {
		DB.Where("status = ?", Status).Offset((Page - 1) * PageSize).Limit(PageSize).Find(&good)
	}
	return
}

func (g *Good) UpdateStatus(id, Status int) error {
	return DB.Model(&g).Where("id = ?", id).Update("status", Status).Error
}
